//
//  LXMinusPlusView.m
//  灵秀
//
//  Created by 李田 on 17/3/19.
//  Copyright © 2017年 tianyao. All rights reserved.
//

#import "LXMinusPlusView.h"

@interface LXMinusPlusView ()

@property (weak, nonatomic) IBOutlet UIButton *minusBtn;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@end
@implementation LXMinusPlusView

#pragma mark - 4.0 set方法
- (void)setMinusCount:(NSInteger)minusCount {
    
    _minusCount = minusCount;
    
    //如果个数为0 隐藏 减号 和 数量Label
    _minusBtn.hidden = (minusCount == 0);
    _countLabel.hidden = (minusCount == 0);

    _countLabel.text = @(minusCount).description;
}

#pragma mark - 3.0 点击加号按钮
- (IBAction)plusAction:(UIButton *)sender {
    
    self.minusCount++;
    
    self.isPlus = YES;
    
    if([_delegate respondsToSelector:@selector(minusPlusView:withCount:)]){
        
        [_delegate minusPlusView:self withCount:self.minusCount];
    }
    
}

#pragma mark - 2.0 点击减号按钮
- (IBAction)minusAction:(UIButton *)sender {
 
    self.minusCount--;
    
    self.isPlus = NO;
    
    if([_delegate respondsToSelector:@selector(minusPlusView:withCount:)]){
        
        [_delegate minusPlusView:self withCount:self.minusCount];
    }
    
}

#pragma mark - 1.0 加载xib
+ (instancetype)minusPlusView{
    
    UINib *nib = [UINib nibWithNibName:@"LXMinusPlusView" bundle:nil];
    return [[nib instantiateWithOwner:nil options:nil] lastObject];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    self.minusCount = 0;
}
@end
